﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Intelsi.Entity;

namespace Intelsi.DataAcces
{
    public class BancoDAO : MasterDataAccess, IBancoDAO
    {
        

        public List<Banco> GetAllFromBanco()
        {
            var query = from p in Context.Bancoes
                        orderby p.IdBanco
                        select p;

            return query.ToList();
        }

        public Banco GetAllFromBancoById(int id)
        {
            return Context.Bancoes.Find(id);
        }

        public void AddBanco(Banco banco)
        {
            Context.Bancoes.Add(banco);
            Context.SaveChanges();
        }

        public void ActualizarBanco(Banco banco)
        {
            Context.Entry(banco).State = System.Data.EntityState.Modified;
            Context.SaveChanges();
        }

        public void EliminarBanco(int id)
        {
            var existe = Context.Bancoes.Find(id);

            if (existe != null)
            {
                Context.Bancoes.Remove(existe);
                Context.SaveChanges();
            }
        }


        public List<Banco> GetAllFromBancoByCriterio(string criterio)
        {
            var query = from b in Context.Bancoes
                        select b;

            if (criterio != null)
            {
                query = query.Where(b => b.Nombre.ToUpper().StartsWith(criterio.ToUpper()) ||
                                        b.Nombre.ToUpper().Contains(criterio.ToUpper())

                    );

            }

            return query.OrderBy(b => b.IdBanco).ToList();
        }
    }

}
